-- arena_summoner
-- Create by chengb Dec/30/2015
-- 技能: 角斗台冈布奥召唤

-- 角斗台中召唤元素的位置
local ARENA_SUMMON_POS = 29;

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 已召唤次数
        local summonTimes = source.dbase:query("summon_times");
        local maxTimes = para[2];
        if summonTimes  == nil then
            summonTimes = 0;
        end

        -- 达到召唤上限，则不再召唤
        if summonTimes >= maxTimes then
            return {};
        end

        -- 如果已经死亡了
        if source:isDead() then
            return {};
        end

        local rand = DungeonM.getRandSeed("summoner_skill");

        local pos = ARENA_SUMMON_POS;

        -- 随机选一个召唤物
        local elements = para[1];
        local element = elements[rand % #elements + 1];

        -- 召唤一个怪物
        DungeonM.transGridToMonster(pos, element);

        -- 记录召唤次数
        summonTimes = summonTimes + 1;
        source.dbase:set("summon_times", summonTimes);

        return { source, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        local elements = string.explode(arr[1], "+");
        for index, element in pairs(elements) do
            elements[index] = tonumber(element);
        end

        return {elements, tonumber(arr[2]),};
    end,


    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
}

